<link rel="stylesheet" type="text/css" href="../style/comment.css">
<?php 
    $mypic = $_SESSION["picture"];
    $myid = $_SESSION["id"];
?>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js" type="text/javascript"></script>
<script src="../js/comment.js" type="text/javascript"></script>

<p>페이스북회원 코멘트</p>
<div class="fb-comments" data-numposts="5" data-colorscheme="light"></div>

<hr />

<p>일반회원 코멘트</p>

<div class="comment_box">
    
    <div class="comment">
        <form method="get" action="../module/comment_lab_process.php">
            <img src=<?=$mypic?> />
            <textarea title="댓글 입력..." required="1" placeholder="댓글 입력..." name="text" role="textbox" aria-autocomplete="list" autocomplete="off" aria-expanded="false"></textarea>
            <input type="hidden" name="id" value="<?=$myid?>"/>
            <input value="댓글 달기" type="submit"/>
        </form>
    </div>
    
    <ul class="comment_list">
        <?php 
        include "../module/sendquery_db.php";
        $db = dbservice::getInstance();
        $queryString = "select user.name,user.picture,comment_lab.content,comment_lab.ctime,comment_lab.cid from user join comment_lab on user.id=comment_lab.uid order by comment_lab.cid desc";
        $result = $db->sendquery($queryString);
        
        foreach($result as $row){ 
            $cid = $row['cid']; ?>
        <li class="comment_item">
            <img src=<?=$row['picture']?> />
            <span class="comment_item_name"><?=$row['name']?></span>
            <div class="comment_item_content">
                <div class="comment_item_content_text"><?=$row['content']?></div>
                <div class="comment_item_content_buttons">
                    <a class="comment_item_content_buttons_reply" id=<?="replybt_".$cid?>>댓글달기</a> · 
                    <a class="comment_item_content_buttons_like">좋아요</a> · 
                    <abbr class="comment_item_content_buttons_timestamp"><?=$row['ctime']?></abbr>
                </div>
            </div>
            
            <div class="comment_reply" id=<?="targetform_".$cid?>>
                <form action="../module/reply_lab_process.php">
                    <input type="hidden" name="cid" value="<?=$row['cid']?>"/>
                    <input type="hidden" name="id" value="<?=$myid?>"/>
                    <img src=<?=$mypic?> />
                    <textarea title="댓글 입력..." required="1" placeholder="댓글 입력..." name="text" role="textbox" aria-autocomplete="list" autocomplete="off" aria-expanded="false"></textarea>
                    <input value="댓글 달기" type="submit"/>
                </form>
            </div>
            <ul class="comment_reply_list">
                <?php 
                
                $queryString2 ="select reply_lab.rtext,reply_lab.ctime,user.name,user.picture from reply_lab join comment_lab on reply_lab.cid = comment_lab.cid join user on reply_lab.uid=user.id where comment_lab.cid=$cid";
                $result2 = $db->sendquery($queryString2);
                foreach($result2 as $row2){ ?>
                <li class="comment_reply_list_item comment_item">
                    <img src=<?=$row2['picture']?>/>
                    <span class="comment_reply_list_item_name comment_item_name"><?=$row2['name']?></span>
                    <div class="comment_reply_list_item_content comment_item_content">
                        <div class="comment_reply_list_item_text comment_item_content_text"><?=$row2['rtext']?></div>
                        <div class="comment_reply_list_item_buttons comment_item_content_buttons">
                            <a class="comment_reply_list_item_buttons_like comment_item_content_buttons_like">좋아요</a> · 
                            <abbr class="comment_reply_list_item_buttons_timestamp comment_item_content_buttons_timestamp"><?=$row2['ctime']?></abbr>
                        </div>   
                    </div>
                </li>
                <?php } ?>
            </ul>
        </li>
    <?php } ?>
    </ul>
</div>